package cn.e3.search.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import search.SearchResult;
import cn.e3.search.service.SearchResultService;

@Controller
public class SearchResultController {
	@Autowired
	private SearchResultService searchResultService;
	@Value("${Search_result_rows}")
	private int rows;
	@RequestMapping("/search")
	public String search(String keyword,@RequestParam(defaultValue="1") int page,Model model) throws Exception{
		keyword=new String(keyword.getBytes("iso-8859-1"), "UTF-8");
		SearchResult searchResult = searchResultService.search(keyword, page, rows);
		model.addAttribute("query", keyword);
		model.addAttribute("totalPages", searchResult.getTotalPages());
		model.addAttribute("page", page);
		model.addAttribute("recordCount", searchResult.getRecordCount());
		model.addAttribute("itemList", searchResult.getList());
		return "search";
	}
}
